Skip to content

Conversation

@HanKuanChen
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Han-Kuan Chen (HanKuanChen)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/114965.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+8-8)
  • (modified) llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll (+37)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 427b8bd0e75ab0..b14465ecc1dc91 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15374,9 +15374,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
     case Instruction::ShuffleVector: {
       Value *V;
       if (SLPReVec && !E->isAltShuffle()) {
-        assert(E->ReuseShuffleIndices.empty() &&
-               "Not support ReuseShuffleIndices yet.");
-        assert(E->ReorderIndices.empty() && "Not support ReorderIndices yet.");
         setInsertPointAfterBundle(E);
         Value *Src = vectorizeOperand(E, 0, PostponedPHIs);
         if (E->VectorizedValue) {
@@ -15394,6 +15391,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
                   [&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; });
         V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
         propagateIRFlags(V, E->Scalars, VL0);
+        if (auto *I = dyn_cast<Instruction>(V))
+          V = propagateMetadata(I, E->Scalars);
+        V = FinalShuffle(V, E);
       } else {
         assert(E->isAltShuffle() &&
                ((Instruction::isBinaryOp(E->getOpcode()) &&
@@ -15524,11 +15524,11 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
           transformScalarShuffleIndiciesToVector(VecTy->getNumElements(), Mask);
         }
         V = Builder.CreateShuffleVector(V0, V1, Mask);
-      }
-      if (auto *I = dyn_cast<Instruction>(V)) {
-        V = propagateMetadata(I, E->Scalars);
-        GatherShuffleExtractSeq.insert(I);
-        CSEBlocks.insert(I->getParent());
+        if (auto *I = dyn_cast<Instruction>(V)) {
+          V = propagateMetadata(I, E->Scalars);
+          GatherShuffleExtractSeq.insert(I);
+          CSEBlocks.insert(I->getParent());
+        }
       }
 
       E->VectorizedValue = V;
diff --git a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
index 1fc0b0306d1194..39ba9d52d11e9b 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
@@ -82,3 +82,40 @@ entry:
   store <4 x i32> %4, ptr %8, align 4
   ret void
 }
+
+define void @test4(ptr %in) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LABEL0:%.*]]
+; CHECK:       label0:
+; CHECK-NEXT:    br label [[LABEL2:%.*]]
+; CHECK:       label1:
+; CHECK-NEXT:    br label [[LABEL2]]
+; CHECK:       label2:
+; CHECK-NEXT:    br label [[LABEL0]]
+;
+entry:
+  br label %label0
+
+label0:
+  %0 = load <8 x float>, ptr %in, align 4
+  %1 = shufflevector <8 x float> %0, <8 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+  %2 = shufflevector <8 x float> %0, <8 x float> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+  %3 = call <4 x float> @llvm.fma.v4f32(<4 x float> %1, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %4 = call <4 x float> @llvm.fma.v4f32(<4 x float> %2, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %5 = call <4 x float> @llvm.fma.v4f32(<4 x float> %1, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %6 = call <4 x float> @llvm.fma.v4f32(<4 x float> %2, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  br label %label2
+
+label1:
+  br label %label2
+
+label2:
+  %7 = phi <4 x float> [ %3, %label0 ], [ zeroinitializer, %label1 ]
+  %8 = phi <4 x float> [ %4, %label0 ], [ zeroinitializer, %label1 ]
+  %9 = phi <4 x float> [ %5, %label0 ], [ zeroinitializer, %label1 ]
+  %10 = phi <4 x float> [ %6, %label0 ], [ zeroinitializer, %label1 ]
+  br label %label0
+}
+
+declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>)

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2024

@llvm/pr-subscribers-vectorizers

Author: Han-Kuan Chen (HanKuanChen)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/114965.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+8-8)
  • (modified) llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll (+37)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 427b8bd0e75ab0..b14465ecc1dc91 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15374,9 +15374,6 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
     case Instruction::ShuffleVector: {
       Value *V;
       if (SLPReVec && !E->isAltShuffle()) {
-        assert(E->ReuseShuffleIndices.empty() &&
-               "Not support ReuseShuffleIndices yet.");
-        assert(E->ReorderIndices.empty() && "Not support ReorderIndices yet.");
         setInsertPointAfterBundle(E);
         Value *Src = vectorizeOperand(E, 0, PostponedPHIs);
         if (E->VectorizedValue) {
@@ -15394,6 +15391,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
                   [&SVSrc](int Mask) { return SVSrc->getShuffleMask()[Mask]; });
         V = Builder.CreateShuffleVector(SVSrc->getOperand(0), NewMask);
         propagateIRFlags(V, E->Scalars, VL0);
+        if (auto *I = dyn_cast<Instruction>(V))
+          V = propagateMetadata(I, E->Scalars);
+        V = FinalShuffle(V, E);
       } else {
         assert(E->isAltShuffle() &&
                ((Instruction::isBinaryOp(E->getOpcode()) &&
@@ -15524,11 +15524,11 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
           transformScalarShuffleIndiciesToVector(VecTy->getNumElements(), Mask);
         }
         V = Builder.CreateShuffleVector(V0, V1, Mask);
-      }
-      if (auto *I = dyn_cast<Instruction>(V)) {
-        V = propagateMetadata(I, E->Scalars);
-        GatherShuffleExtractSeq.insert(I);
-        CSEBlocks.insert(I->getParent());
+        if (auto *I = dyn_cast<Instruction>(V)) {
+          V = propagateMetadata(I, E->Scalars);
+          GatherShuffleExtractSeq.insert(I);
+          CSEBlocks.insert(I->getParent());
+        }
       }
 
       E->VectorizedValue = V;
diff --git a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
index 1fc0b0306d1194..39ba9d52d11e9b 100644
--- a/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
+++ b/llvm/test/Transforms/SLPVectorizer/revec-shufflevector.ll
@@ -82,3 +82,40 @@ entry:
   store <4 x i32> %4, ptr %8, align 4
   ret void
 }
+
+define void @test4(ptr %in) {
+; CHECK-LABEL: @test4(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LABEL0:%.*]]
+; CHECK:       label0:
+; CHECK-NEXT:    br label [[LABEL2:%.*]]
+; CHECK:       label1:
+; CHECK-NEXT:    br label [[LABEL2]]
+; CHECK:       label2:
+; CHECK-NEXT:    br label [[LABEL0]]
+;
+entry:
+  br label %label0
+
+label0:
+  %0 = load <8 x float>, ptr %in, align 4
+  %1 = shufflevector <8 x float> %0, <8 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
+  %2 = shufflevector <8 x float> %0, <8 x float> zeroinitializer, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
+  %3 = call <4 x float> @llvm.fma.v4f32(<4 x float> %1, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %4 = call <4 x float> @llvm.fma.v4f32(<4 x float> %2, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %5 = call <4 x float> @llvm.fma.v4f32(<4 x float> %1, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  %6 = call <4 x float> @llvm.fma.v4f32(<4 x float> %2, <4 x float> zeroinitializer, <4 x float> zeroinitializer)
+  br label %label2
+
+label1:
+  br label %label2
+
+label2:
+  %7 = phi <4 x float> [ %3, %label0 ], [ zeroinitializer, %label1 ]
+  %8 = phi <4 x float> [ %4, %label0 ], [ zeroinitializer, %label1 ]
+  %9 = phi <4 x float> [ %5, %label0 ], [ zeroinitializer, %label1 ]
+  %10 = phi <4 x float> [ %6, %label0 ], [ zeroinitializer, %label1 ]
+  br label %label0
+}
+
+declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>)

@HanKuanChen HanKuanChen force-pushed the slp-revec-shufflevector-FinalShuffle branch from 5e0653e to b3ecc2a Compare November 6, 2024 09:17
@HanKuanChen HanKuanChen merged commit c6091cd into llvm:main Nov 7, 2024
6 of 8 checks passed
@HanKuanChen HanKuanChen deleted the slp-revec-shufflevector-FinalShuffle branch November 7, 2024 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants